package com.film.admincontroller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.FilmType;
import com.film.service.FilmTypeService;
import com.film.service.impl.FilmTypeServiceImpl;

@WebServlet("/deleteFilmType.do")
public class DeleteFilmTypeController extends HttpServlet{
	private FilmTypeService filmTypeService = new FilmTypeServiceImpl();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String typeId = request.getParameter("typeId");
		String flag = request.getParameter("flag");
		//检查是否关联中间表
		List<Integer> lists = filmTypeService.selectFilmTypeAndFilmMiddleSurface(Integer.parseInt(typeId));
		if(lists.size()==0) {
			//执行删除
			filmTypeService.deleteFilmType(Integer.parseInt(typeId));
			List<FilmType> adminFilmTypes = filmTypeService.selectAllFilmType();
			session.setAttribute("adminFilmTypes", adminFilmTypes);
			session.setAttribute("adminFilmTypesSize", adminFilmTypes.size());
			session.setAttribute("adminFilmType", adminFilmTypes);
			response.sendRedirect("admin_jsp/filmTypeExhibition.jsp?flag=1");
			
		}else {
			session.setAttribute("typeMsg", "该类型有电影绑定，暂时删除不了");
			response.sendRedirect("admin_jsp/filmTypeExhibition.jsp?flag=1");
		}
	}
}
